#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    int numSubarrayProductLessThanK(vector<int>& nums, int k) {
        if (k <= 1) {
            return 0;
        }

        int res = 0;
        int left = 0;
        int prod = 1;
        for (int right = 0; right < nums.size(); ++right) {
            prod *= nums[right];
            while (prod >= k) {
                prod /= nums[left];
                ++left;
            }
            res += right - left + 1;
        }
        return res;
    }
};

int main() {
    Solution s;

    vector<int> nums1{10, 5, 2, 6};
    vector<int> nums2{1, 2, 3};

    assert(s.numSubarrayProductLessThanK(nums1, 100) == 8);
    assert(s.numSubarrayProductLessThanK(nums2, 0) == 0);

    return 0;
}